package com.reeygu.base;

import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ExecutionException;

public class CompletableFutureDemo {
    public static void main(String[] args) throws ExecutionException, InterruptedException {
        //异步调用，无返回值形式
        CompletableFuture<Void> completableFuture = CompletableFuture.runAsync(() -> {
            System.out.println(Thread.currentThread().getName() + " A1 ");
        });

        //异步调用，有返回值形式
        CompletableFuture<Integer> completableFutureValue = CompletableFuture.supplyAsync(() -> {
            System.out.println(Thread.currentThread().getName() + " A1 ");
            return 200;
        });
        completableFutureValue.whenComplete((result, e) -> {
            System.out.println("返回结果" + result + " 异常" + e);
        }).get();
    }
}
